﻿@* 
Project: Aguafrommars/TheIdServer
Copyright (c) 2022 @Olivier Lefebvre
*@
@page
@using Microsoft.AspNetCore.Mvc.Localization
@namespace Aguacongas.TheIdServer.Areas.Identity.Pages.Account.Manage
@inject IViewLocalizer Localizer
@model GrantsModel
@{
    ViewData["Title"] = Localizer["Client Application Access"];
    ViewData["ActivePage"] = ManageNavPages.Grants;
}
<div class="row">
    <div class="col-sm-10">
        <h4>
            @ViewData["Title"]
        </h4>
        <h5>@Localizer["Below is the list of applications you have given access to and the names of the resources they have access to."]</h5>
    </div>
</div>
<div class="grants">

    @if (Model.Grants.Any() == false)
    {
        <div class="row">
            <div class="col-sm-8">
                <div class="alert alert-info">
                    @Localizer["You have not given access to any applications"]
                </div>
            </div>
        </div>
    }
    else
    {
        foreach (var grant in Model.Grants)
        {
            <div class="row grant">
                <div class="col-2">
                    @if (grant.ClientLogoUrl != null)
                    {
                        <img src="@grant.ClientLogoUrl" alt="logo">
                    }
                    else
                    {
                        <img src="/icons8-app-symbol-96.png" alt="logo">
                    }
                </div>
                <div class="col-7">
                    <div class="clientname">@grant.ClientName</div>
                    <div>
                        <span class="created">@Localizer["Created:"]</span> @grant.Created.ToString("yyyy-MM-dd")
                    </div>
                    @if (grant.Expires.HasValue)
                    {
                        <div>
                            <span class="expires">@Localizer["Expires:"]</span> @grant.Expires.Value.ToString("yyyy-MM-dd")
                        </div>
                    }
                    @if (grant.IdentityGrantNames.Any())
                    {
                        <div>
                            <div class="granttype">@Localizer["Identity Grants"]</div>
                            <ul>
                                @foreach (var name in grant.IdentityGrantNames)
                                {
                                    <li>@name</li>
                                }
                            </ul>
                        </div>
                    }
                    @if (grant.ApiGrantNames.Any())
                    {
                        <div>
                            <div class="granttype">@Localizer["API Grants"]</div>
                            <ul>
                                @foreach (var name in grant.ApiGrantNames)
                                {
                                    <li>@name</li>
                                }
                            </ul>
                        </div>
                    }
                </div>
                <div class="col">
                    <form method="post">
                        <input type="hidden" name="clientId" value="@grant.ClientId">
                        <button class="btn btn-lg btn-danger" asp-page-handler="Revoke">@Localizer["Revoke Access"]</button>
                    </form>
                </div>
            </div>
        }
    }
</div>